#include "soft_usb.h"
#include <Arduino.h>

#ifndef _USB_Client_Connector_H
#define _USB_Client_Connector_H

class USBClientConnector;

class USBClientConnectorCallbacks {
public:
    virtual void usb_onDisconnect(USBClientConnector *pConnector) { ; }
};

// BLE HID
class USBClientConnector {
public:
    uint8_t usbNum = -1;           // USB设备号
    uint16_t cfgNum = 0;           // USB接口号
    uint16_t interfaceNum = 0;     // USB接口号
    uint16_t hidReportDescLen = 0; // 报表描述符长度
    uint8_t epMin = 0;             // 该接口下最小端点号
    uint8_t epMax = 0;             // 该接口下最大端点号
    uint8_t interval = 0;          // 扫描间隔
    uint8_t _DeviceID[4] = {0};    // 设备标识（Vendor id+Product id ）
    int _type = 0;                 //  (0:未知  1：键盘 2:鼠标)
    int _keyboard_mode = 0;        // 0: 美式键盘; 1:日式键盘
    int _status = 0;               // 连接状态    (-1:连接失败 0:未连接 1:已连接 2：已识别(HID))
private:
    int _cntFail = 0; // 尝试失败次数

    USBClientConnectorCallbacks *_pCallbacks = nullptr; // 事件通知对象

    typedef void (*setOnRecvData_t)(USBClientConnector *_pConnect, uint8_t *dataBuf, int nLen);
    void (*onRecvDataCallback)(USBClientConnector *_pConnect, uint8_t *dataBuf, int nLen);

public:
    void destory();
    void clear();
    void onRecvData(uint8_t *dataBuf, int nLen);

    // 控制键盘灯
    void setLED(uint8_t flags);

    void setUSBClientConnectorCallbacks(USBClientConnectorCallbacks *pCallbacks);
    void setOnRecvData(setOnRecvData_t cb);
};

#endif
